<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/xlrblog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/xlrblog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/xlrblog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/xlrblog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/xlrblog/css/main.css">


<link rel="stylesheet" href="/xlrblog/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/xlrblog/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="Maven是专门用于管理和构建Java项目的工具。它的主要功能有：  提供了一套标准化的项目结构 所有IDE使用Maven构建的项目结构完全一样，因此Maven项目可以在不同的IDE中通用  提供了一套标准化的构建流程（编译，测试，打包，发布……）  提供了一套依赖管理机制 管理项目所依赖的第三方资源(jar包、插件…)   Maven简介Apache Maven是一个项目管理和构建工具，它基于项">
<meta property="og:type" content="article">
<meta property="og:title" content="Maven基础">
<meta property="og:url" content="https://gitee.com/xlr0306/2023/01/07/Maven%E5%9F%BA%E7%A1%80/index.html">
<meta property="og:site_name" content="君不见的博客">
<meta property="og:description" content="Maven是专门用于管理和构建Java项目的工具。它的主要功能有：  提供了一套标准化的项目结构 所有IDE使用Maven构建的项目结构完全一样，因此Maven项目可以在不同的IDE中通用  提供了一套标准化的构建流程（编译，测试，打包，发布……）  提供了一套依赖管理机制 管理项目所依赖的第三方资源(jar包、插件…)   Maven简介Apache Maven是一个项目管理和构建工具，它基于项">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://note.youdao.com/yws/api/personal/file/WEB8d3d820679f566bd960399e46785a316?method=download&shareKey=a39ebd8ec0a132c879426c7f11781d38">
<meta property="article:published_time" content="2023-01-07T09:48:46.000Z">
<meta property="article:modified_time" content="2023-01-07T14:33:49.191Z">
<meta property="article:author" content="君不见">
<meta property="article:tag" content="Note">
<meta property="article:tag" content="Maven">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://note.youdao.com/yws/api/personal/file/WEB8d3d820679f566bd960399e46785a316?method=download&shareKey=a39ebd8ec0a132c879426c7f11781d38">

<link rel="canonical" href="https://gitee.com/xlr0306/2023/01/07/Maven%E5%9F%BA%E7%A1%80/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Maven基础 | 君不见的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/xlrblog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">君不见的博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">记录生活中的点点滴滴</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/xlrblog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/xlrblog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/xlrblog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/xlrblog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/xlr0306/2023/01/07/Maven%E5%9F%BA%E7%A1%80/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/xlrblog/images/avatar.gif">
      <meta itemprop="name" content="君不见">
      <meta itemprop="description" content="君不见，黄河之水天上来，奔流到海不复回。">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="君不见的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Maven基础
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2023-01-07 17:48:46 / 修改时间：22:33:49" itemprop="dateCreated datePublished" datetime="2023-01-07T17:48:46+08:00">2023-01-07</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/xlrblog/categories/Java-Web/" itemprop="url" rel="index"><span itemprop="name">Java Web</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>Maven是专门用于管理和构建Java项目的工具。<br>它的主要功能有：</p>
<ul>
<li><p>提供了一套标准化的项目结构</p>
<p>所有IDE使用Maven构建的项目结构完全一样，因此Maven项目可以在不同的IDE中通用</p>
</li>
<li><p>提供了一套标准化的构建流程（编译，测试，打包，发布……）</p>
</li>
<li><p>提供了一套依赖管理机制</p>
<p>管理项目所依赖的第三方资源(jar包、插件…)</p>
</li>
</ul>
<h2 id="Maven简介"><a href="#Maven简介" class="headerlink" title="Maven简介"></a>Maven简介</h2><p>Apache Maven是一个项目管理和构建工具，它基于项目对象模型(POM)的概念，通过一小段描述信息来管理项目的构建、报告和文档</p>
<p>官网: <a target="_blank" rel="noopener" href="https://maven.apache.org/">https://maven.apache.org</a></p>
<h3 id="Maven模型"><a href="#Maven模型" class="headerlink" title="Maven模型"></a>Maven模型</h3><p><img src="https://note.youdao.com/yws/api/personal/file/WEB8d3d820679f566bd960399e46785a316?method=download&shareKey=a39ebd8ec0a132c879426c7f11781d38" alt="1673063001054"></p>
<h3 id="仓库分类"><a href="#仓库分类" class="headerlink" title="仓库分类"></a>仓库分类</h3><p><strong>本地仓库</strong>:自己计算机上的一个目录</p>
<p><strong>中央仓库</strong>:由Maven团队维护的全球唯一的仓库</p>
<ul>
<li>地址: <a target="_blank" rel="noopener" href="https://repo1.maven.org/maven2">https://repo1.maven.org/maven2</a></li>
</ul>
<p><strong>远程仓库(私服)</strong>:一般由公司团队搭建的私有仓库</p>
<p>当项目中使用坐标引入对应依赖jar包后，首先会查找本地仓库中是否有对应的jar包。<strong>如果有，则在项目直接引用；如果没有，则去中央仓库中下载对应的jar包到本地仓库。</strong></p>
<p>还可以搭建远程仓库,将来jar包的查找顺序则变为:</p>
<p>本地仓库→远程仓库→中央仓库</p>
<h2 id="Maven安装配置"><a href="#Maven安装配置" class="headerlink" title="Maven安装配置"></a>Maven安装配置</h2><ol>
<li><p>从官网下载 apache-maven-3.8.6-bin.zip(Windows是这个)，然后将其解压</p>
</li>
<li><p>配置环境变量:</p>
<p>将解压后的maven的bin的目录路径复制 ，添加到系统变量的Path下</p>
<p>在命令行输入mvn -version检查是否成功，正常情况如下：</p>
<figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Apache Maven <span class="number">3</span>.<span class="number">8</span>.<span class="number">6</span> (<span class="number">84538</span>c9988a25aec085021c365c560670ad80f63)</span><br><span class="line">Maven home: E:\SoftwareFile\maven_tools\apache-maven-<span class="number">3</span>.<span class="number">8</span>.<span class="number">6</span></span><br><span class="line">Java version: <span class="number">1</span>.<span class="number">8</span>.<span class="number">0</span>_202, vendor: Oracle Corporation, runtime: E:\java\jdk\jdk1.<span class="number">8</span>.<span class="number">0</span>_202\jre</span><br><span class="line">Default locale: zh_CN, platform encoding: GBK</span><br><span class="line">OS name: &quot;windows <span class="number">10</span>&quot;, version: &quot;<span class="number">10</span>.<span class="number">0</span>&quot;, arch: &quot;amd64&quot;, family: &quot;windows&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>配置本地仓库:</p>
<p>修改conf&#x2F;settings.xml中的&lt; localRepository&gt;为一个指定目录</p>
<p>例如：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">localRepository</span>&gt;</span>E:\\SoftwareFile\\maven_tools\\maven_repository<span class="tag">&lt;/<span class="name">localRepository</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>配置阿里云私服:</p>
<p>修改conf&#x2F;settings.xml中的&lt;mirrors&gt;标签，为其添加如下子标签:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">mirror</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">id</span>&gt;</span>alimaven<span class="tag">&lt;/<span class="name">id</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">mirrorOf</span>&gt;</span>central<span class="tag">&lt;/<span class="name">mirrorOf</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">name</span>&gt;</span>aliyun maven<span class="tag">&lt;/<span class="name">name</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">url</span>&gt;</span>http://maven.aliyun.com/nexus/content/repositories/central/<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mirror</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="Maven基本使用"><a href="#Maven基本使用" class="headerlink" title="Maven基本使用"></a>Maven基本使用</h2><h3 id="Maven常用命令"><a href="#Maven常用命令" class="headerlink" title="Maven常用命令"></a>Maven常用命令</h3><p>右键点击开始，打开Windows PowerShell，切换到项目的目录。</p>
<p>或者进入项目所在文件夹，在看得见pom.xml的文件夹里shift+右键，注意不要选中文件，打开PowerShell。</p>
<p>然后就可以通过输入mvn xxx来执行命令了。</p>
<ul>
<li><p>mvn compile：编译</p>
<p>执行该命令会在项目下生成一个target目录，编译后的字节码文件就会放在该目录下面。</p>
</li>
<li><p>mvn clean：清理</p>
<p>执行该命令会删除项目下的 target 目录 </p>
</li>
<li><p>mvn test：测试</p>
<p>执行该命令会所有的测试代码</p>
</li>
<li><p>mvn package：打包</p>
<p>执行该命令会将当前项目打包成一个jar包，并将其放在target目录下</p>
</li>
<li><p>mvn install：安装</p>
<p>执行该命令会将当前项目打成jar包，并安装到本地仓库。</p>
</li>
</ul>
<h3 id="Maven生命周期"><a href="#Maven生命周期" class="headerlink" title="Maven生命周期"></a>Maven生命周期</h3><p>Maven 对项目构建的生命周期划分为3套： </p>
<p>clean ：清理工作。 </p>
<p>default ：核心工作，例如编译，测试，打包，安装等。 </p>
<p>site ： 产生报告，发布站点等。这套声明周期一般不会使用。 </p>
<p>同一套生命周期内，执行后面的命令，前面的所有命令会自动执行。</p>
<p>例如：当我们执行 install （安装）命令时，它会先执行 compile 命令，再执行 test 命令，再执行 package 命令，最后执行install 命令。 </p>
<h2 id="IDEA配置Maven"><a href="#IDEA配置Maven" class="headerlink" title="IDEA配置Maven"></a>IDEA配置Maven</h2><h3 id="IDEA配置Maven环境"><a href="#IDEA配置Maven环境" class="headerlink" title="IDEA配置Maven环境"></a>IDEA配置Maven环境</h3><ol>
<li>点击File -&gt; Settings… -&gt; Build Tools -&gt; Maven</li>
<li>在Maven home path 选择maven的路径，如：E:&#x2F;SoftwareFile&#x2F;maven_tools&#x2F;apache-maven-3.8.6</li>
<li>在User settings file 将后面的Override勾上，选择配置文件路径，如：E:\SoftwareFile\maven_tools\apache-maven-3.8.6\conf\settings.xml</li>
<li>点击OK</li>
</ol>
<h3 id="Maven坐标详解"><a href="#Maven坐标详解" class="headerlink" title="Maven坐标详解"></a>Maven坐标详解</h3><p>什么是坐标？ </p>
<ul>
<li>Maven 中的坐标是资源(可以是插件、依赖、当前项目)的唯一标识 </li>
<li>使用坐标来定义项目或引入项目中需要的依赖</li>
</ul>
<p>Maven 坐标主要组成 </p>
<ul>
<li>groupId：定义当前Maven项目隶属组织名称（通常是域名反写，例如：org.springframework） </li>
<li>artifactId：定义当前Maven项目名称（通常是模块名称，例如 spring-context） </li>
<li>version：定义当前项目版本号</li>
</ul>
<p>例如：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-context<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">version</span>&gt;</span>5.3.23<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="IDEA创建Maven项目"><a href="#IDEA创建Maven项目" class="headerlink" title="IDEA创建Maven项目"></a>IDEA创建Maven项目</h3><ol>
<li>首先创建项目，New Project</li>
<li>填写好名称等，其中Location为项目存放路径，Build System选择Maven。另外最下方还有Advanced Settings，其中GroupId为组织名，ArtifactId为模块名</li>
</ol>
<h2 id="依赖管理"><a href="#依赖管理" class="headerlink" title="依赖管理"></a>依赖管理</h2><h3 id="引入jar包"><a href="#引入jar包" class="headerlink" title="引入jar包"></a>引入jar包</h3><p>使用坐标引入jar包：</p>
<p>在pom.xml中编写标签，如下：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">properties</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">maven.compiler.source</span>&gt;</span>8<span class="tag">&lt;/<span class="name">maven.compiler.source</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">maven.compiler.target</span>&gt;</span>8<span class="tag">&lt;/<span class="name">maven.compiler.target</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">project.build.sourceEncoding</span>&gt;</span>UTF-8<span class="tag">&lt;/<span class="name">project.build.sourceEncoding</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">properties</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>mysql<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mysql-connector-java<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">version</span>&gt;</span>8.0.31<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>然后点击IDEA右侧上方的Maven，选择刷新按钮点击即可</p>
<p>具体的坐标可以到如下网站进行搜索 </p>
<p><a target="_blank" rel="noopener" href="https://mvnrepository.com/">https://mvnrepository.com/</a></p>
<p>快捷方式导入jar包的坐标：</p>
<p>在pom.xml 中按alt + insert 或者 alt + fn + insert，选择Add dependency，然后在搜索框中搜索，点击Add就行</p>
<h3 id="依赖范围"><a href="#依赖范围" class="headerlink" title="依赖范围"></a>依赖范围</h3><p>通过设置坐标的依赖范围(scope)，可以设置对应jar包的作用范围：编译环境、测试环境、运行环境。 </p>
<table>
<thead>
<tr>
<th align="center">依赖范围</th>
<th align="center">编译classpath</th>
<th align="center">测试classpath</th>
<th align="center">运行classpath</th>
</tr>
</thead>
<tbody><tr>
<td align="center">compile</td>
<td align="center">Y</td>
<td align="center">Y</td>
<td align="center">Y</td>
</tr>
<tr>
<td align="center">test</td>
<td align="center">-</td>
<td align="center">Y</td>
<td align="center">-</td>
</tr>
<tr>
<td align="center">provided</td>
<td align="center">Y</td>
<td align="center">Y</td>
<td align="center">-</td>
</tr>
<tr>
<td align="center">runtime</td>
<td align="center">-</td>
<td align="center">Y</td>
<td align="center">Y</td>
</tr>
<tr>
<td align="center">system</td>
<td align="center">Y</td>
<td align="center">Y</td>
<td align="center">-</td>
</tr>
</tbody></table>
<p><strong>如果引入坐标不指定 scope 标签时，默认就是 compile 值。</strong></p>
<p>system和provided的区别是，使用system范围的依赖时必须通过systemPath元素显式地指定依赖文件的路径。</p>
<p>由于此类依赖不是通过Maven仓库解析的，而且往往与本机系统绑定，可能造成构建的不可移植，因此应该谨慎使用。systemPath元素可以引用环境变量。例如： </p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>javax.sql<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>jdbc-stdext<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">scope</span>&gt;</span>system<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">systemPath</span>&gt;</span>$&#123;java.home&#125;/lib/rt.jar<span class="tag">&lt;/<span class="name">systemPath</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/xlrblog/tags/Note/" rel="tag"># Note</a>
              <a href="/xlrblog/tags/Maven/" rel="tag"># Maven</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/xlrblog/2023/01/06/%E8%93%9D%E6%A1%A5%E6%9D%AF%E9%83%A8%E5%88%86%E9%A2%98%E7%9B%AE/" rel="prev" title="蓝桥杯部分题目">
      <i class="fa fa-chevron-left"></i> 蓝桥杯部分题目
    </a></div>
      <div class="post-nav-item">
    <a href="/xlrblog/2023/01/15/MyBatis%E5%AD%A6%E4%B9%A0/" rel="next" title="MyBatis学习">
      MyBatis学习 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Maven%E7%AE%80%E4%BB%8B"><span class="nav-number">1.</span> <span class="nav-text">Maven简介</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Maven%E6%A8%A1%E5%9E%8B"><span class="nav-number">1.1.</span> <span class="nav-text">Maven模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%93%E5%BA%93%E5%88%86%E7%B1%BB"><span class="nav-number">1.2.</span> <span class="nav-text">仓库分类</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Maven%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE"><span class="nav-number">2.</span> <span class="nav-text">Maven安装配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Maven%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8"><span class="nav-number">3.</span> <span class="nav-text">Maven基本使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Maven%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="nav-number">3.1.</span> <span class="nav-text">Maven常用命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Maven%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="nav-number">3.2.</span> <span class="nav-text">Maven生命周期</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#IDEA%E9%85%8D%E7%BD%AEMaven"><span class="nav-number">4.</span> <span class="nav-text">IDEA配置Maven</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#IDEA%E9%85%8D%E7%BD%AEMaven%E7%8E%AF%E5%A2%83"><span class="nav-number">4.1.</span> <span class="nav-text">IDEA配置Maven环境</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Maven%E5%9D%90%E6%A0%87%E8%AF%A6%E8%A7%A3"><span class="nav-number">4.2.</span> <span class="nav-text">Maven坐标详解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#IDEA%E5%88%9B%E5%BB%BAMaven%E9%A1%B9%E7%9B%AE"><span class="nav-number">4.3.</span> <span class="nav-text">IDEA创建Maven项目</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BE%9D%E8%B5%96%E7%AE%A1%E7%90%86"><span class="nav-number">5.</span> <span class="nav-text">依赖管理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%BC%95%E5%85%A5jar%E5%8C%85"><span class="nav-number">5.1.</span> <span class="nav-text">引入jar包</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BE%9D%E8%B5%96%E8%8C%83%E5%9B%B4"><span class="nav-number">5.2.</span> <span class="nav-text">依赖范围</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="君不见"
      src="/xlrblog/images/avatar.gif">
  <p class="site-author-name" itemprop="name">君不见</p>
  <div class="site-description" itemprop="description">君不见，黄河之水天上来，奔流到海不复回。</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/xlrblog/archives/">
        
          <span class="site-state-item-count">50</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/decxlr" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;decxlr" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">君不见</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/xlrblog/lib/anime.min.js"></script>
  <script src="/xlrblog/lib/velocity/velocity.min.js"></script>
  <script src="/xlrblog/lib/velocity/velocity.ui.min.js"></script>

<script src="/xlrblog/js/utils.js"></script>

<script src="/xlrblog/js/motion.js"></script>


<script src="/xlrblog/js/schemes/pisces.js"></script>


<script src="/xlrblog/js/next-boot.js"></script>




  




  
<script src="/xlrblog/js/local-search.js"></script>













  

  

</body>
</html>
